package com.zyf.chapter02.behavior.state.mario;

/**
 * 马里奥有限状态机
 * 分支逻辑法：用于不复杂的状态机
 * @author yifeng
 */
public class MarioStateMachine_Brance {
    private int score;
    private State currentState;

    public MarioStateMachine_Brance() {
        this.score = 0;
        this.currentState = State.SMALL;
    }

    public void obtainMushRoom() {
        if (!currentState.equals(State.CAPE) || !currentState.equals(State.FIRE)) {
            currentState = State.SUPER;
            score += 100;
        }
    }

    public void obtainCape() {
        if (!currentState.equals(State.FIRE)) {
            currentState = State.CAPE;
            score += 200;
        }
    }

    public void obtainFireFlower() {
        if (!currentState.equals(State.CAPE)) {
            currentState = State.FIRE;
            score += 300;
        }
    }

    public void meetMonster() {
        if (currentState.equals(State.SUPER)) {
            score -= 100;
        } else if (currentState.equals(State.CAPE)) {
            score -= 200;
        } else if (currentState.equals(State.FIRE)) {
            score -= 300;
        }
    }

    public int getScore() {
        return score;
    }

    public State getCurrentState() {
        return currentState;
    }
}
